import { constantRoutes, routerMap } from "@/router";
import { serverRouterMap } from "@/api/permission";
import Layout from "@/views/layout/Layout";

function generateAsyncRouter(routerMap, serverRouterMap) {
    serverRouterMap.forEach(function(item, index) {
        item.component = routerMap[item.component];
        if (item.children && item.children.length > 0) {
            generateAsyncRouter(routerMap, item.children);
        }
    });
    return serverRouterMap;
}
/**
 * 通过meta.role判断是否与当前用户权限匹配
 * @param roles
 * @param route
 */
function hasPermission(roles, route) {
    if (route.meta && route.meta.roles) {
        return roles.some(role => route.meta.roles.includes(role));
    } else {
        return true;
    }
}

function getHomeRoutes(roles) {
    var home = {
        // path: '/',
        // component: Layout,
        // redirect: '/homePage',
        // meta: {
        //   title: '首页',
        //   icon: 'guide'
        // },
        // children: [
        // ]
    };
    return home;
}
/**
 * 递归过滤异步路由表，返回符合用户角色权限的路由表
 * @param routes asyncRoutes
 * @param roles
 */
export function filterAsyncRoutes(routes, roles) {
    const res = [];

    routes.forEach(route => {
        const tmp = {...route };
        if (hasPermission(roles, tmp)) {
            if (tmp.children) {
                tmp.children = filterAsyncRoutes(tmp.children, roles);
            }
            res.push(tmp);
        }
    });

    return res;
}

const permission = {
    state: {
        routes: [],
        addRoutes: []
    },
    mutations: {
        SET_ROUTES: (state, routes) => {
            state.addRoutes = routes;
            state.routes = constantRoutes.concat(routes);
        }
    },
    actions: {
        GenerateRoutes({ commit }, data) {
            return new Promise(resolve => {
                const { roles } = data;
                serverRouterMap().then(response => {
                    let accessedRouters;
                    const json = response.data.data;
                    const json1 = [
                        {
                            path: "/projects",
                            component: "Layout",
                            redirect: "/projects",
                            meta: {
                                title: "项目管理",
                                icon: "xiangmu"
                            },
                            children: [{
                                    path: "/projects",
                                    component: "projects",
                                    name: "projects",
                                    meta: {
                                        title: "项目列表",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: false
                                },
                                // {
                                //   path: '/project_group',
                                //   component: 'project_group',
                                //   name: 'project_group',
                                //   meta: { title: '分组管理', icon: 'xiangmu', affix: true, },
                                //   noCache: false,
                                // },
                                {
                                    path: "/project_group_detail",
                                    component: "project_group_detail",
                                    name: "project_group_detail",
                                    meta: {
                                        title: "分组项目",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: false,
                                    hidden: true
                                },
                                {
                                    path: "/project_detail",
                                    component: "project_detail",
                                    name: "/project_detail",
                                    meta: {
                                        title: "项目详情",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/add_projects",
                                    component: "add_projects",
                                    name: "/add_projects",
                                    meta: {
                                        title: "添加项目",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 新医院管理
                        {
                            path: "/Newhospital",
                            component: "Layout",
                            redirect: "null",
                            meta: {
                                title: "医院管理",
                                icon: "yiyuan"
                            },
                            children:[
                                {
                                path: "/hospitalList",
                                component: "hospitalList",
                                name: "hospitalList",
                                meta: {
                                    title: "医院管理",
                                    icon: "yiyuan"
                                },
                                noCache: true
                            }, 
                            {
                                path: "/addHospital",
                                component: "addHospital",
                                name: "/addHospital",
                                meta: {
                                    title: "添加",
                                    icon: "yiyuan",
                                    affix: true
                                },
                                noCache: true,
                                hidden: true,
                                breadcrumb: false
                            },
                                
                            ]
                        },
                        //   app营销设置
                        {
                            path: "/appList",
                            component: "Layout",
                            redirect: "null",
                            meta: {
                                title: "app营销管理",
                                icon: "xiangmu"
                            },
                            children: [{
                                    path: "/swiperMange",
                                    component: "swiperMange",
                                    name: "swiperMange",
                                    meta: {
                                        title: "首页轮播图",
                                        icon: "yiyuan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/keywordMange",
                                    component: "keywordMange",
                                    name: "/keywordMange",
                                    meta: {
                                        title: "关键词管理",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/add_keyword",
                                    component: "add_keyword",
                                    name: "/add_keyword",
                                    meta: {
                                        title: "添加关键词",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },

                                {
                                    path: "/mainEntrance",
                                    component: "mainEntrance",
                                    name: "/mainEntrance",
                                    meta: {
                                        title: "主要入口区",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/addEntrance",
                                    component: "addEntrance",
                                    name: "/addEntrance",
                                    meta: {
                                        title: "添加",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/marketingMange",
                                    component: "marketingMange",
                                    name: "/marketingMange",
                                    meta: {
                                        title: "营销矩阵区",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/hotRecommended",
                                    component: "hotRecommended",
                                    name: "/hotRecommended",
                                    meta: {
                                        title: "热门推荐",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/addHot",
                                    component: "addHot",
                                    name: "/addHot",
                                    meta: {
                                        title: "添加",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/popupMange",
                                    component: "popupMange",
                                    name: "/popupMange",
                                    meta: {
                                        title: "弹窗配置",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/splashScreen",
                                    component: "splashScreen",
                                    name: "/splashScreen",
                                    meta: {
                                        title: "闪屏配置",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/dropdown",
                                    component: "dropdown",
                                    name: "/dropdown",
                                    meta: {
                                        title: "首页下拉效果配置",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/add",
                                    component: "add",
                                    name: "/add",
                                    meta: {
                                        title: "添加闪屏",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }

                            ]
                        },
                        // 礼包管理
                        {
                            path: "/goods",
                            component: "Layout",
                            redirect: "/goods",
                            children: [{
                                    path: "goods",
                                    component: "goods",
                                    name: "goods",
                                    meta: {
                                        title: "礼包管理",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/goods_detail",
                                    component: "goods_detail",
                                    name: "/goods_detail",
                                    meta: {
                                        title: "礼包详情",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/add_goods_new",
                                    component: "add_goods_new",
                                    name: "/add_goods_new",
                                    meta: {
                                        title: "添加礼包",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 卡券列表
                        {
                            path: "/coupon",
                            component: "Layout",
                            redirect: "/coupon",
                            children: [{
                                    path: "coupon",
                                    component: "coupon",
                                    name: "coupon",
                                    meta: {
                                        title: "卡券列表",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true
                                },
                                {
                                    path: "couponList",
                                    component: "couponList",
                                    name: "couponList",
                                    hidden: true,
                                    meta: {
                                        title: "优惠券",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true
                                }
                            ]
                        },

                        // 达人管理
                        {
                            path: "/talent",
                            component: "Layout",
                            redirect: "/talent",
                            children: [{
                                    path: "talent",
                                    component: "talent",
                                    name: "talent",
                                    meta: {
                                        title: "达人管理",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/talent_detail",
                                    component: "talent_detail",
                                    name: "talent_detail",
                                    meta: {
                                        title: "达人详情",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },

                        // 攻略管理
                        {
                            path: "/strategy",
                            component: "Layout",
                            redirect: "/strategy",
                            meta: {
                                title: "攻略管理",
                                icon: "xiangmu"
                            },
                            children: [{
                                    path: "/faq",
                                    component: "faq",
                                    name: "faq",
                                    meta: {
                                        title: "常见问题",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/ad_learning",
                                    component: "ad_learning",
                                    name: "ad_learning",
                                    meta: {
                                        title: "进阶学习",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true
                                }
                            ]
                        },

                        // 分类管理
                        {
                            path: "/class_management",
                            component: "Layout",
                            redirect: "/class_management",
                            children: [{
                                path: "class_management",
                                component: "class_management",
                                name: "class_management",
                                meta: {
                                    title: "分类管理",
                                    icon: "fenlei",
                                    affix: true
                                },
                                noCache: true
                            }]
                        },
                        // 医院管理
                        // {
                        //     path: "/hospital",
                        //     component: "Layout",
                        //     redirect: "/hospital",
                        //     children: [
                        //         {
                        //             path: "/hospital",
                        //             component: "hospital",
                        //             name: "hospital",
                        //             meta: {
                        //                 title: "医院管理",
                        //                 icon: "yiyuan"
                        //             },
                        //             noCache: true
                        //         },
                        //         // 新医院管理列表php接口
                           
                        //         {
                        //             path: "/add_hospital_new",
                        //             component: "add_hospital_new",
                        //             name: "/add_hospital_new",
                        //             meta: {
                        //                 title: "添加医院",
                        //                 icon: "xiangmu",
                        //                 affix: true
                        //             },
                        //             noCache: true,
                        //             hidden: true,
                        //             breadcrumb: false
                        //         },
                        //         // add_hospital_new
                        //         {
                        //             path: "/addHospitals",
                        //             component: "addHospitals",
                        //             name: "/addHospitals",
                        //             meta: {
                        //                 title: "添加医院",
                        //                 icon: "xiangmu",
                        //                 affix: true
                        //             },
                        //             noCache: true,
                        //             hidden: true,
                        //             breadcrumb: false
                        //         },
                        //     ]
                        // },

                        // 广告位管理
                        {
                            path: "/adv",
                            component: "Layout",
                            redirect: "/adv",
                            meta: {
                                title: "广告位管理",
                                icon: "guanggaoguanli"
                            },
                            children: [{
                                    path: "/pop_up",
                                    component: "pop_up",
                                    name: "pop_up",
                                    meta: {
                                        title: "弹窗管理",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/adv",
                                    component: "adv",
                                    name: "adv",
                                    meta: {
                                        title: "会员营销位",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/vip_slideshow",
                                    component: "vip_slideshow",
                                    name: "vip_slideshow",
                                    meta: {
                                        title: "会员轮播图",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/slideshow",
                                    component: "slideshow",
                                    name: "slideshow",
                                    meta: {
                                        title: "轮播图管理",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/marketing",
                                    component: "marketing",
                                    name: "marketing",
                                    meta: {
                                        title: "营销位管理",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/add_marketing",
                                    component: "add_marketing",
                                    name: "add_marketing",
                                    meta: {
                                        title: "添加营销位",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/fresh_news",
                                    component: "fresh_news",
                                    name: "fresh_news",
                                    meta: {
                                        title: "新鲜事管理",
                                        icon: "guanggaoguanli"
                                    },
                                    noCache: true
                                }
                            ]
                        },
                        // 新医生管理路由
                        {
                            path: "/docotrMange",
                            component: "Layout",
                            redirect: "null",
                            children: [{
                                    path: "/doctorList",
                                    component: "doctorList",
                                    name: "doctorList",
                                    meta: {
                                        title: "医生管理",
                                        icon: "yiyuan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/doctorInfo",
                                    component: "doctorInfo",
                                    name: "/doctorInfo",
                                    meta: {
                                        title: "添加医生",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 用户管理
                        {
                            path: "/users",
                            component: "Layout",
                            redirect: "/users",
                            meta: {
                                title: "用户管理",
                                icon: "peoples"
                            },
                            children: [{
                                    path: "/users",
                                    component: "users",
                                    name: "users",
                                    meta: {
                                        title: "用户列表",
                                        icon: "peoples"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/vip_setting",
                                    component: "vip_setting",
                                    name: "vip_setting",
                                    meta: {
                                        title: "会员权益",
                                        icon: "peoples"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/user_detail",
                                    component: "user_detail",
                                    name: "user_detail",
                                    meta: {
                                        title: "用户详情",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 拼团管理
                        {
                            path: "/groups",
                            component: "Layout",
                            redirect: "/groups",
                            meta: {
                                title: "拼团管理",
                                icon: "pintuanguanli"
                            },
                            children: [{
                                    path: "/groups",
                                    component: "groups",
                                    name: "groups",
                                    meta: { title: "拼团列表" },
                                    noCache: true
                                },
                                {
                                    path: "/group_setting",
                                    component: "group_setting",
                                    name: "group_setting",
                                    meta: { title: "拼团设置" },
                                    noCache: true
                                },
                                {
                                    path: "/group_detail",
                                    component: "group_detail",
                                    name: "/group_detail",
                                    meta: {
                                        title: "拼团详情",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 订单管理
                        {
                            path: "/orders",
                            component: "Layout",
                            redirect: "/orders",
                            meta: {
                                title: "订单管理",
                                icon: "dingdan"
                            },
                            children: [{
                                    path: "/orders",
                                    component: "orders",
                                    name: "/orders",
                                    meta: {
                                        title: "订单列表",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                // {
                                //     path: "/user_order",
                                //     component: "user_order",
                                //     name: "/user_order",
                                //     meta: {
                                //         title: "会员开通订单信息记录",
                                //         icon: "dingdan"
                                //     },
                                //     hidden: false,
                                //     noCache: true,
                                //     breadcrumb: false
                                // },
                                {
                                    path: "/order_detail",
                                    component: "order_detail",
                                    name: "/order_detail",
                                    meta: {
                                        title: "订单详情",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 素材管理
                        {
                            path: "/material",
                            component: "Layout",
                            redirect: "/material",
                            children: [{
                                path: "material",
                                component: "material",
                                name: "material",
                                meta: {
                                    title: "素材管理",
                                    icon: "sucai"
                                },
                                noCache: true
                            }]
                        },
                        // 财务管理
                        {
                            path: "/finance_refund_money",
                            component: "Layout",
                            redirect: "null",
                            meta: {
                                title: "财务管理",
                                icon: "money"
                            },
                            children: [{
                                    path: "/finance_refund_money",
                                    component: "finance_refund_money",
                                    name: "finance_refund_money",
                                    meta: {
                                        title: "财务回款",
                                        noCache: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/cash_list",
                                    component: "cash_list",
                                    name: "cash_list",
                                    meta: {
                                        title: "提现列表",
                                        noCache: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/picture_detail",
                                    component: "picture_detail",
                                    name: "picture_detail",
                                    meta: {
                                        title: "消费凭证详情",
                                        icon: "xiangmu",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/PLUSWithdrawalAudit",
                                    component: "PLUSWithdrawalAudit",
                                    name: "PLUSWithdrawalAudit",
                                    meta: {
                                        title: "PLUS提现列表",
                                        affix: true
                                    }
                                },
                                {
                                    path: "/PLUSMemberAccountManage",
                                    component: "PLUSMemberAccountManage",
                                    name: "PLUSMemberAccountManage",
                                    meta: {
                                        title: "PLUS会员账户管理",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },

                                {
                                    path: "/withdrawableBalanceInfo",
                                    component: "withdrawableBalanceInfo",
                                    name: "withdrawableBalanceInfo",
                                    meta: {
                                        title: "可提现余额详情",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true
                                        // breadcrumb: false
                                },
                                {
                                    path: "/CommissionWithdrawalAudit",
                                    component: "CommissionWithdrawalAudit",
                                    name: "CommissionWithdrawalAudit",
                                    meta: {
                                        title: "佣金提现审核",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/reconciliation",
                                    component: "reconciliation",
                                    name: "reconciliation",
                                    meta: {
                                        title: "机构对账管理",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                },

                                {
                                    path: "/tixianCheck",
                                    component: "tixianCheck",
                                    name: "tixianCheck",
                                    meta: {
                                        title: "机构提现审核",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                },

                                {
                                    path: "/tixianDetail",
                                    component: "tixianDetail",
                                    name: "tixianDetail",
                                    meta: {
                                        title: "查看详情",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                },

                                {
                                    path: "/accountMange",
                                    component: "accountMange",
                                    name: "accountMange",
                                    meta: {
                                        title: "机构账户管理",
                                        affix: true
                                    },
                                    noCache: true,
                                    breadcrumb: false
                                },

                                {
                                    name: "OrganizationBankCardManagement",
                                    path: "/OrganizationBankCardManagement",
                                    component: "OrganizationBankCardManagement",
                                    meta: {
                                        title: "机构银行卡管理",
                                        // icon: "dingdan",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    name: "OrganizationRechangeManagement",
                                    path: "/OrganizationRechangeManagement",
                                    component: "OrganizationRechangeManagement",
                                    meta: {
                                        title: "机构充值管理",
                                        // icon: "dingdan",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                },

                                {
                                    name: "OrganizationRechangeDetail",
                                    path: "/OrganizationRechangeDetail",
                                    component: "OrganizationRechangeDetail",
                                    meta: {
                                        title: "机构充值详情",
                                        // icon: "dingdan",
                                        affix: true
                                    },
                                    noCache: true,
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 权限管理
                        {
                            path: "/role",
                            component: "Layout",
                            redirect: "/role",
                            meta: {
                                title: "权限管理",
                                icon: "quanxian"
                            },
                            children: [{
                                    path: "/role",
                                    component: "role",
                                    name: "role",
                                    meta: {
                                        title: "角色管理",
                                        noCache: true
                                    }
                                },
                                {
                                    path: "/add_role",
                                    component: "add_role",
                                    name: "add_role",
                                    meta: {
                                        title: "添加角色",
                                        noCache: true
                                    },
                                    hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    path: "/member",
                                    component: "member",
                                    name: "member",
                                    meta: {
                                        title: "成员管理",
                                        noCache: true
                                    }
                                },
                                {
                                    path: "/add_member",
                                    component: "add_member",
                                    name: "add_member",
                                    meta: {
                                        title: "添加成员",
                                        noCache: true
                                    },
                                    hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        },
                        // 新零售体系
                        {
                            path: "/NewRetailSystemMange",
                            component: "Layout",
                            redirect: "null",
                            meta: {
                                title: "新零售体系",
                                icon: "form"
                            },
                            children: [{
                                    path: "/RegionalManagement",
                                    component: "RegionalManagement",
                                    name: "RegionalManagement",
                                    meta: {
                                        title: "大区管理",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/ProvinceManagement",
                                    component: "ProvinceManagement",
                                    name: "ProvinceManagement",
                                    meta: {
                                        title: "省份管理",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/cityManagement",
                                    component: "cityManagement",
                                    name: "cityManagement",
                                    meta: {
                                        title: "城市管理",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/addRegional",
                                    component: "addRegional",
                                    name: "addRegional",
                                    meta: { title: "添加大区" },
                                    hidden: true,
                                    noCache: true
                                },
                                {
                                    path: "/AddProvince",
                                    component: "AddProvince",
                                    name: "AddProvince",
                                    meta: { title: "添加省份" },
                                    hidden: true,
                                    noCache: true
                                },
                                {
                                    path: "/AddCity",
                                    component: "AddCity",
                                    name: "AddCity",
                                    meta: { title: "添加城市" },
                                    hidden: true,
                                    noCache: true
                                },

                                {
                                    path: "/organizationalManagement",
                                    component: "organizationalManagement",
                                    name: "organizationalManagement",
                                    meta: {
                                        title: "机构管理",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/SponsorManagement",
                                    component: "SponsorManagement",
                                    name: "SponsorManagement",
                                    meta: {
                                        title: "发起人管理",
                                        icon: "user"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/CityPartnerManagement",
                                    component: "CityPartnerManagement",
                                    name: "CityPartnerManagement",
                                    meta: {
                                        title: "城市合伙人管理",
                                        icon: "user"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/traditionalForm",
                                    component: "traditionalForm",
                                    name: "traditionalForm",
                                    meta: {
                                        title: "传统报单",
                                        icon: "xiangmu"
                                    },
                                    noCache: true
                                },
                                // formChecked报单审核
                                {
                                    path: "/formChecked",
                                    component: "formChecked",
                                    name: "formChecked",
                                    meta: { title: "审核" },
                                    hidden: true,
                                    noCache: true
                                },
                                {
                                    path: "/AddSponsor",
                                    component: "AddSponsor",
                                    name: "AddSponsor",
                                    meta: { title: "添加发起人" },
                                    hidden: true,
                                    noCache: true
                                },
                                {
                                    path: "/AddCityPartner",
                                    component: "AddCityPartner",
                                    name: "AddCityPartner",
                                    meta: {
                                        title: "添加城市合伙人"
                                    },
                                    hidden: true,
                                    noCache: true
                                }

                                // {
                                //   path: '/ServiceProviderManagement',
                                //   component: 'ServiceProviderManagement',
                                //   name: 'ServiceProviderManagement',
                                //   meta: { title: '服务商管理', icon: 'user' },
                                //   noCache: true
                                // }
                            ]
                        },
                        // 会员中心
                        {
                            path: "/MemberCenter",
                            component: "Layout",
                            redirect: "/MemberCenter",
                            meta: {
                                title: "会员中心",
                                icon: "form"
                            },
                            children: [{
                                path: "/MemberManagement",
                                component: "MemberManagement",
                                name: "MemberManagement",
                                meta: {
                                    title: "会员管理",
                                    icon: "dingdan"
                                },
                                noCache: true
                            }]
                        },
                        // 订单中心
                        {
                            path: "/OrderCenter",
                            component: "Layout",
                            redirect: "/OrderCenter",
                            meta: {
                                title: "订单中心",
                                icon: "form"
                            },
                            children: [{
                                    path: "/GiftBagOrder",
                                    component: "GiftBagOrder",
                                    name: "GiftBagOrder",
                                    meta: {
                                        title: "礼包订单",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/ProjectOrder",
                                    component: "ProjectOrder",
                                    name: "ProjectOrder",
                                    meta: {
                                        title: "项目订单",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/GroupOrder",
                                    component: "GroupOrder",
                                    name: "GroupOrder",
                                    meta: {
                                        title: "拼团订单",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/RefundOrder",
                                    component: "RefundOrder",
                                    name: "RefundOrder",
                                    meta: {
                                        title: "礼包订单退款",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/ProjectOrderRefund",
                                    component: "ProjectOrderRefund",
                                    name: "ProjectOrderRefund",
                                    meta: {
                                        title: "项目订单退款",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                }
                            ]
                        },
                        // 财务中心
                        {
                            path: "/FinancialCenter",
                            component: "Layout",
                            redirect: "/FinancialCenter",
                            meta: {
                                title: "财务中心",
                                icon: "form"
                            },
                            children: [{
                                    path: "/CommissionPerformance",
                                    component: "CommissionPerformance",
                                    name: "CommissionPerformance",
                                    meta: {
                                        title: "订单业绩",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/ServiceProvidersRewardManage",
                                    component: "ServiceProvidersRewardManage",
                                    name: "ServiceProvidersRewardManage",
                                    meta: {
                                        title: "服务商奖励管理",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    path: "/ServiceProviderWithdrawalAudit",
                                    component: "ServiceProviderWithdrawalAudit",
                                    name: "ServiceProviderWithdrawalAudit",
                                    meta: {
                                        title: "服务商提现审核",
                                        icon: "dingdan"
                                    },
                                    noCache: true
                                },
                                {
                                    name: "SponsorPartnerAccountManagement",
                                    path: "/SponsorPartnerAccountManagement",
                                    component: "SponsorPartnerAccountManagement",
                                    meta: {
                                        title: "发起人合伙人账户管理",
                                        icon: "dingdan",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                },
                                {
                                    name: "SponsorPartnerBankCardManagement",
                                    path: "/SponsorPartnerBankCardManagement",
                                    component: "SponsorPartnerBankCardManagement",
                                    meta: {
                                        title: "发起人合伙人银行卡管理",
                                        icon: "dingdan",
                                        affix: true
                                    },
                                    noCache: true,
                                    // hidden: true,
                                    breadcrumb: false
                                }
                            ]
                        }
                    ];
                    var asyncRouterMap = generateAsyncRouter(routerMap, json1);
                    accessedRouters = filterAsyncRoutes(asyncRouterMap, roles);
                    var res = accessedRouters.concat({
                        path: "*",
                        redirect: "/404",
                        hidden: true
                    });
                    //   res.unshift(getHomeRoutes(roles))
                    commit("SET_ROUTES", res);
                    resolve(res);
                });
            });
        }
    }
};

export default permission;